package info.techgeek.labs.robot;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.util.Timer;
import java.util.TimerTask;

public class MyMovingMouse {
	
	 	private final Timer timer = new Timer();
	    private final int minutes;
	    private static Robot robot ;
	    
	    public MyMovingMouse(int minutes) {
	        this.minutes = minutes;
	    }

	    
	    public void start() {
	    	System.out.println("start()");
	        timer.schedule(new TimerTask() {
	            public void run() {
	            	System.out.println("run");
	                playSound();
	                timer.cancel();
	            }
	            private void playSound() {
	                System.out.println("Your egg is ready!");
	                // Start a new thread to play a sound...
	            	robot.mouseWheel(-700);
	            }
	        }, minutes * 1000);
	    }

    public static void main(String[] args) {
    	System.out.println("Begin");
    	MyMovingMouse myMovingMouse = new MyMovingMouse(4);
    	
        try {
        	robot = new Robot();
            robot.mouseMove(560, 1000);
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
            
            myMovingMouse.start();
            
            robot.mouseMove(560, 500);
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
            
            robot.mouseWheel(-100);
            System.out.println("End");
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }
    
    
}
